//
// Created by lingzhitech on 25-9-24.
//
//
// Created by lingzhitech on 25-9-24.
//

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include "../material/Utils.hpp"




void biggies(std::vector<std::string> &words,
             std::vector<std::string>::size_type sz) {
    elimDups(words); // put words in alphabetical order and remove duplicates
    stable_sort(words.begin(), words.end(), [](const std::string &a, const std::string &b) { return a.size() < b.size(); });
    auto wc = std::partition(words.begin(), words.end(), [sz](const auto& word){ return word.size() < sz;});    //use stable_partition    auto wc = std::stable_partition(words.begin(), words.end(), [sz](const auto& word){ return word.size() < sz;});
    auto count = words.end() - wc;
    std::cout << count << " " << make_plural(count, "word", "s")
            << " of length " << sz << " or longer" << std::endl;
    for_each(wc, words.end(),
             [](const std::string &s) { std::cout << s << " "; });
    std::cout << std::endl;
}


int main() {
    std::vector<std::string> words{"dog", "cat", "dog", "apple", "apple", "bat", "hello", "world"};
    biggies(words, 4);
}
